package org.fing.edu.uy.esbadp.motor.comunication;

import java.util.List;

import org.fing.edu.uy.esbadp.core.constants.ConfigConstants;
import org.fing.edu.uy.esbadp.core.constants.JMXServiceConstants;
import org.fing.edu.uy.esbadp.core.entity.PropertiesMonitoring;
import org.fing.edu.uy.esbadp.core.utils.JMXManager;
import org.fing.edu.uy.esbadp.logger.LoggerADP;
import org.fing.edu.uy.esbadp.motor.config.MgrConfig;

public class AdmRequirementsComunication {
	
	
	 private static java.util.logging.Logger logger = LoggerADP.getLogger(AdmRequirementsComunication.class.getSimpleName());
		
	
	/**
	 * Funcion encargarda de obtener la lista de requerimientos de servicios que no se cumplen 
	 * @return List Retorna una lista de String con los nombres de los requerimientos de servicios que no se estan satisfaciendo.
	 * @throws Exception En caso de error al invocar la operacion JMX retorna error.
	 */
	@SuppressWarnings("unchecked")
	public static List<String> getEvaluationServiceRequeriments(Long serviceId, PropertiesMonitoring properties) throws Exception {
		//config call operations getAdpFlowForService
		String jmxServiceURL = MgrConfig.getInstance().getProperty(ConfigConstants.JMXEsbAdpURL);
		String mBeanName = JMXServiceConstants.JMXServiceRequerimentMBean;
		Object[] arguments = {serviceId, properties};
		String[] signature = {Long.class.getName(), PropertiesMonitoring.class.getName()};
		
		//get evaluation service requeriments for adaptation
		Object result = JMXManager.callOperation(jmxServiceURL, mBeanName, "getEvaluationServiceRequeriments", arguments, signature);
		if(result != null){
			return (List<String>) result;
		}else{
			logger.info("There is no service requeriment that needs a new adaptation.");
			return null;
		}
	}

}
